package com.buybuyyi.stylistcrm.resource.controllers.order;

import com.buybuyyi.stylistcrm.resource.controllers.DefaultController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import stylistcrm.core.query.ResultPagerModel;
import stylistcrm.core.services.order.dto.OrderGoodsDto;
import stylistcrm.core.services.order.dto.PurchaseOrderDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.enums.EnumExceptionCode;
import stylistcrm.core.services.order.exception.BizException;
import stylistcrm.core.services.order.service.PurchaseOrderService;

import java.util.List;

/**
 * Created by cheny on 2016/9/5.
 */
@Controller
@RequestMapping("/order")
public class PurchaseOrderController extends DefaultController{

    @Autowired
    private PurchaseOrderService purchaseOrderService;

    @ResponseBody
    @RequestMapping("/createpurchaseorder")
    public Boolean createPurchaseOrder(PurchaseOrderDto purchaseOrderDto) throws BizException {
        super.checkLogin();
        if(null==purchaseOrderDto){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        Boolean saveFlag=purchaseOrderService.createPurchaseOrder(purchaseOrderDto);
        return saveFlag;
    }
    @ResponseBody
    @RequestMapping("/getpurchaseorderpagelist")
    public ResultPagerModel<PurchaseOrderDto> getPurchaseOrderPageList(QueryOrderConditionDto queryCondition) throws BizException {
        Long userId=super.checkLogin();
        if(null==queryCondition){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        queryCondition.setDesignerId(userId.intValue());
        return purchaseOrderService.getPageList(queryCondition);
    }
    @ResponseBody
    @RequestMapping("/getpurchaseorderdetail")
    public PurchaseOrderDto getPurchaseOrderDetail(Integer orderId) throws BizException {
        super.checkLogin();
        if(null==orderId){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        return purchaseOrderService.selectByPrimaryKey(orderId);
    }
    @ResponseBody
    @RequestMapping("/getpurchasegoodslist")
    public List<OrderGoodsDto> getPurchaseGoodsList() throws BizException {
        Long userId=super.checkLogin();
        return purchaseOrderService.getGoodsList(userId);
    }
}
